const BodyParser = require('body-parser')
const Mock = require('mockjs')

let dataList = Mock.mock({
    "list|100-200": [
        {
            name: "@cname",
            "sex|1":[0, 1],
            "college|1": ['网站工程','通识教育','传媒'],
            "class|1": ['2208A', '2209A', '2210A'],
            id: "@id",
            "dorm|100-999":1,
            date: "@date(yyyy-MM-dd)",
            "num|50-100": 1
        }
    ]
})

module.exports = (app) => {

    app.use(BodyParser.json())

    // 获取列表
    app.post('/api/getList', (req, res) => {
        res.send({
            code: 1,
            data: dataList.list
        })
    })

    // 删除
    app.delete('/api/delete', (req, res) => {
        // 获取前端传来的参数
        const { id } = req.query;

        dataList.list = dataList.list.filter(item => item.id !== id)

        res.send({
            code: 1,
            msg: '删除成功'
        })
    })

}